$(function($){
	$("#toAdd").click(function(){
		var url =baseContextPath + "mailController/toAdd";
		window.open(url, "", 
		"height=400, width=800, top=150, left=320,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,location=no, resizable=auto");
	});
	
	
	$("#doAdd").click(function(){
		var vFD = new FormData(document.getElementById('form'));

        var oXHR = new XMLHttpRequest();
        oXHR.addEventListener('load', function(e){
            var response = e.target.responseText;
            var data = JSON.parse(response);
            if(data.result == 'success'){
                alert("创建成功");
                window.location.reload();
                window.close();
            }else if(data.result == 'error'){
                alert("请选择图片类型");
                return;
            }else{
                alert("异常");
                return;
            }

        }, false);
        oXHR.addEventListener('error', function(e){
            alert("输入参数异常");
            return;
        }, false);
        oXHR.addEventListener('abort', function(){
        }, false);
        oXHR.open('POST', baseContextPath + 'mailController/sendMail');
        oXHR.send(vFD);
	});
})